<!doctype html>
<html style="height: 0px !important">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>大奔农庄</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>   
</head>
<style>
	input::-webkit-input-placeholder { /* WebKit, Blink, Edge */
	    color:    #fff;
	}
	input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
	   color:    #fff;
	}
	input::-moz-placeholder { /* Mozilla Firefox 19+ */
	   color:    #fff;
	}
	input:-ms-input-placeholder { /* Internet Explorer 10-11 */
	   color:    #fff;
</style>
<body class="dl-bg-100">
	<div class="dl-logo cd_dl-logo">
		<img src="../../image/logo.png">
	</div>
	<div class="dl-kuang">
	<form id="form">
		<!-- 输入手机号 -->
		<img src="../../image/dl-yh.png" class="aui-pull-left di-img-posi">
		<input type="number" class="dl-text" placeholder="请输入用户名/手机号" id="account" name="account">
		<div class="bai-1"></div>
		<!-- 输入密码 -->
		<img src="../../image/dl-ma.png" class="aui-pull-left di-img-posi">
		<input type="password" class="dl-pw" placeholder="请输入密码" id="password" name="password">
		<div class="bai-1"></div>
		<!-- 登录 -->
		<input class="aui-btn aui-btn-bai aui-btn-outlined aui-btn-fff dl-button" type="button" value="登录" onclick="doLogin();">
		<span class="aui-pull-left dl-span" onclick="openReg();">免费注册</span>
		<span class="aui-pull-right dl-span" onclick="openFindPwd();">忘记密码</span>
	</form>	
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script>
var db_key = 'user',db_user ,ajpushID='';
var JPushID_interval;
var myfrom,myParam = {};
apiready = function() {
    myfrom = $api.byId('form');
}

function syncJPushID() {
    ajpushID = $api.getStorage('ajpushID');
    try {
        if (ajpushID != '' && typeof(ajpushID)!='undefined') {
            window.clearInterval(JPushID_interval);
            _doLogin();
        }
    }catch(e){}
    return true;
}
//登录验证
function doLogin() {
    var preg = new RegExp(/1\d{10}/);
    if(!preg.test(myfrom.account.value)) {
        api.toast({msg: '请输入正确的手机号码！'});
        return false;
    }
    if (myfrom.password.value=='') {
        api.toast({msg: '密码不能为空'});
        return false;
    }
    
    api.showProgress();//显示加载进度框
    
    //JPushID_interval = setInterval("syncJPushID()", 500);
//  ajpushID = $api.getStorage('ajpushID');
    _doLogin();
}

function _doLogin() {
    myParam.rtk = RSapi.myrtk;
    myParam.account = myfrom.account.value;
    myParam.password = myfrom.password.value;
//  myParam.jpushid = ajpushID;
    //alert(myParam.jpushid);
//      myParam.logsinfo = api.systemType+' '+api.systemVersion+' '+api.deviceModel;//用于记录登录日志
    
    api.ajax({
        url: RSapi.base+RSapi.Mlogin,
        method: 'post',
        cache: false,
        timeout: 30,
        dataType: 'json',
        data: { values: myParam },
    }, function(ret, err){
        api.hideProgress();//隐藏加载进度框
        if(err){
            //alert(JSON.stringify(err));
            api.alert({msg: JSON.stringify(err)});
        }else {
            if (ret.status == 1) {
                //成功了
                db_user = $api.getStorage(db_key);
                try {
                    db_user.islogin = true;
                    db_user.account = myParam.account;
                    db_user.mytoken = ret.mytoken;
                }catch(e){
                    db_user = {};
                    db_user.islogin = true;
                    db_user.account = myParam.account;
                    db_user.mytoken = ret.mytoken;
                }
                $api.setStorage(db_key, db_user);
                
//              var ajpush = api.require('ajpush');
//              ajpush.bindAliasAndTags({alias:'logined'});
                
                //发送登录成功事件
                api.sendEvent({
                    name: 'login_self',
                    extra: {}
                });
                api.alert({msg: '登录成功！'},function(ret,err){
                    api.closeWin();
                });
            }else {
                //失败了
                api.toast({msg: ret.info});
            }
        }
    });
    return false;
}
/*打开找回密码*/
function openFindPwd(){
	api.openWin({
        name: 'win_findpwd',
    	url: '../win/findpwd_win.html'
    });
}
/**注册账号*/
function openReg(){
	api.openWin({
	    name: 'win_register',
	    url: '../win/register_win.html',
	    pageParam: {inself:true}
    });
}
</script>
</html>